package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.service.IEmployeeService;
import cn.wolfcode.rbac.util.CurrentUtil;
import cn.wolfcode.rbac.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/login")
    @ResponseBody
    public Result login(Model model, String username, String password){
        try{
            employeeService.login(username,password);
            return new Result(200,"操作成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500,e.getMessage());

        }


    }

    @RequestMapping("/logout")
    public String logout(){
        CurrentUtil.getSession().invalidate();
        return "redirect:/login.html";
    }
}
